package com.huiquan.dyad.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.dyad.domain.DyadPre;
import com.huiquan.dyad.domain.DyadStdOrder;
import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabDyadStd;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class DyadInitDao extends EnhancedBaseDao<VocabDyadStd> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "DYAD_INIT.";

	public DyadInitDao() {
		super(space);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrievePOMerge() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_PO_MERGE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveOdeCombine() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_O_DE_DYAD_COMBINE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveDyadSynonymy() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_DYAD_SYNONYMY", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveOOCombine() {
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_O_O_DYAD_COMBINE", sqlMapClient);
	}

	public void batchInsertInitPre(List<DyadPre> list) {
		int start = 0, end, size = list.size();
		List<DyadPre> tempList;

		while (start < size) {
			if (start + 500 < size) {
				end = start + 500;
			} else {
				end = size;
			}
			tempList = list.subList(start, end);
			this.insert(space + "BATCH_INSERT_INIT_PRE", tempList, sqlMapClient);
			start += 500;
		}
	}

	public void mergePre() {
		this.insert(space + "MERGE_PRE", sqlMapClient);
	}

	public void deleteUnchecked() {
		this.delete(space + "DELETE_UNCHECKED", sqlMapClient);
	}

	public void insertUncheckedByPre() {
		this.insert(space + "INSERT_UNCHECKED_BY_PRE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<DyadStdOrder> retrieveStdOrder() {
		return (List<DyadStdOrder>) this.list(space + "RETRIEVE_STD_ORDER", sqlMapClient);
	}

	public void batchInsertPage(List<DyadStdOrder> list) {
		this.insert(space + "BATCH_INSERT_PAGE", list, sqlMapClient);
	}

	public void deleteAllPre() {
		this.update(space + "DELETE_ALL_PRE", sqlMapClient);
	}
	public void initOSSearch() {
		this.update(space + "INIT_O_S_SEARCH", sqlMapClient);
	}

}
